//
//  MyBziInfoV.m
//  ZITHER
//
//  Created by weixin on 2018/11/23.
//  Copyright © 2018 weixn. All rights reserved.
//

#import "MyBziInfoV.h"

@implementation MyBziInfoV

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.clipsToBounds = NO;
        self.backgroundColor = [UIColor redColor];
        
//        // 阴影颜色
//        self.layer.shadowColor = [UIColor defaultShadowColor].CGColor;
//        // 阴影偏移，默认(0, -3)
//        self.layer.shadowOffset = CGSizeMake(0,-3);
//        // 阴影透明度，默认0
//        self.layer.shadowOpacity = 1;
//        // 阴影半径，默认3
//        self.layer.shadowRadius = 5;
        
        
        self.layer.masksToBounds = NO;
        self.layer.shadowColor = [UIColor grayColor].CGColor;
        self.layer.shadowOffset = CGSizeMake(0,-3);
        self.layer.shadowOpacity = 0.3;
        self.layer.shadowRadius = 10;
        self.layer.shouldRasterize = YES;
        self.layer.rasterizationScale = [[UIScreen mainScreen] scale];
  
//        [self setShadowType1WithColor:[UIColor defaultShadowColor] offset:CGSizeMake(0, 3) opacity:1 radius:2];
        
//        [self setShadowRadius:10 Opacity:0.4 Color:[UIColor grayColor]];
//        self.layer.shadowOpacity = 1;
//        self.layer.shadowColor = [UIColor grayColor].CGColor;
//        [self setBorderWithColor:[UIColor grayColor] width:1];
//        [self setCornerRadiusWithRadius:1 isMasks:YES];
        
        [self setUI];
        [self setMasonry];
        NSLog(@"");
    }
    return self;
}

-(void)setMasonry{
    
    ////根据后台设置
    [self.imgeMap mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(5);
        make.left.right.equalTo(self).offset(0);
        make.height.mas_equalTo((kScreenW-30)/325.0*235);
    }];
    
    [self.BizName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imgeMap.mas_bottom).offset(10);
        make.left.equalTo(self.BizNameIcon.mas_right).offset(10);
    }];
    
    [self.imgeMapIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.imgeMap.mas_bottom).offset(0);
        make.right.equalTo(self).offset(-20);
        make.height.width.mas_equalTo(32);
    }];
    
    [self.BizNameIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.BizName.mas_centerY).offset(0);
        make.left.equalTo(self).offset(10);
        make.height.width.mas_equalTo(14);
    }];

    [self.BizPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.BizName.mas_bottom).offset(20);
        make.left.equalTo(self.BizNameIcon.mas_right).offset(10);
    }];
    
    [self.BizPhonetext mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.BizPhone.mas_bottom).offset(4);
        make.left.equalTo(self.BizNameIcon.mas_right).offset(10);
    }];

    [self.BizWX mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.BizPhonetext.mas_bottom).offset(15);
        make.left.equalTo(self.BizNameIcon.mas_right).offset(10);
    }];
    
    [self.BizNametext mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.BizWX.mas_bottom).offset(4);
        make.left.equalTo(self.BizNameIcon.mas_right).offset(10);
    }];

    [self.BizAddr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.BizNametext.mas_bottom).offset(16);
        make.left.equalTo(self.BizNameIcon.mas_right).offset(10);
    }];

    [self.BizAddrSub mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.BizAddr.mas_bottom).offset(0);
        make.left.equalTo(self.BizNameIcon.mas_right).offset(10);
    }];


}

-(void)setUI{
    [self addSubview:self.imgeMap];
    [self addSubview:self.BizName];
    [self addSubview:self.BizPhone];
    [self addSubview:self.BizWX];
    [self addSubview:self.BizAddr];
    [self addSubview:self.BizAddrSub];
    [self addSubview:self.imgeMapIcon];
    [self addSubview:self.BizNameIcon];
    [self addSubview:self.BizNametext];
    [self addSubview:self.BizPhonetext];
}

-(void)setModel:(AcceptPriceListModel *)model{
    
    _model = model;
    
    [self.imgeMap sd_setImageWithURL:[NSURL URLWithString:[NSString getMapImageView:_model.latitude markers:_model.longitude]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        //        NSLog(@"map ==== %@ %@ ")
        self.imgeMap.image = image.grayImage;//图片变灰
    }];
    
    self.BizName.text = _model.bizNickName;
    self.BizAddrSub.text = [NSString stringWithFormat:@"%@%@%@",_model.province,_model.city,_model.area];
    self.BizAddr.text = _model.bizAddr;
    
    
    self.BizPhone.text = _model.bizPhone;
    self.BizWX.text = _model.bizWechat;
  
}


-(BaseImageV *)imgeMap{
    if (!_imgeMap) {
        _imgeMap = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, kScreenW, 20) contentMode:2];
    }
    return _imgeMap;
}

-(BaseImageV *)imgeMapIcon{
    if (!_imgeMapIcon) {
        _imgeMapIcon = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 32, 32) contentMode:2];
        _imgeMapIcon.image = [UIImage imageNamed:@"sku_btn_position"];
        _imgeMapIcon.backgroundColor = [UIColor clearColor];
    }
    return _imgeMapIcon;
}


-(BaseImageV *)BizNameIcon{
    if (!_BizNameIcon) {
        _BizNameIcon = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 14, 14) contentMode:2];
        _BizNameIcon.image = [UIImage imageNamed:@"商家信息_商家"];
        _BizNameIcon.backgroundColor = [UIColor clearColor];
    }
    return _BizNameIcon;
}

-(BaseLab *)BizName{
    if (!_BizName) {
        _BizName = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 0, 0) text:@"商家名称" font:12 textColor:[UIColor blackColor] isBold:NO numberOfLines:1];
        _BizName.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:15];
    }
    return _BizName;
}

-(BaseLab *)BizPhone{
    if (!_BizPhone) {
        _BizPhone = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 0, 0) text:@"商家手机" font:12 textColor:[UIColor blackColor] isBold:NO numberOfLines:1];
        _BizPhone.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:14];
        
        
        [[_BizPhone addTag] subscribeNext:^(id x) {
            
            NSMutableString *str=[[NSMutableString alloc]initWithFormat:@"电话号码:%@",self.model.bizPhone];
            
            QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:NULL];
            
            
            QMUIAlertAction *action2 = [QMUIAlertAction actionWithTitle:@"呼叫" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
                //        @strongify(self);

                NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.model.bizPhone]];
                [[UIApplication sharedApplication] openURL:url];
                
            }];
            
            QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"拨打号码" message:@"是否拨打号码" preferredStyle:QMUIAlertControllerStyleAlert];
            
            [alertController addAction:action1];
            [alertController addAction:action2];
            [alertController showWithAnimated:YES];
            
        }];

    }
    return _BizPhone;
}


-(BaseLab *)BizWX{
    if (!_BizWX) {
        _BizWX = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 0, 0) text:@"商家微信" font:12 textColor:[UIColor blackColor] isBold:NO numberOfLines:1];
        _BizWX.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:14];
        [[_BizWX addTag] subscribeNext:^(id x) {
            
            UIPasteboard *pab = [UIPasteboard generalPasteboard];
            NSString *string = self.model.bizWechat;
            [pab setString:string];
            if (pab == nil) {
                [Tools showTips:@"复制失败"];
                return ;
            }else{
                [Tools showTips:@"已复制"];
            }
            
            
            QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:NULL];
            
            
            QMUIAlertAction *action2 = [QMUIAlertAction actionWithTitle:@"跳转" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
                //        @strongify(self);
                NSURL *url = [NSURL URLWithString:@"weixin://"];
                
                [[UIApplication sharedApplication] openURL:url];
                
            }];
            
            QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"跳转微信" message:@"复制成功是否跳转到微信" preferredStyle:QMUIAlertControllerStyleAlert];
            
            [alertController addAction:action1];
            [alertController addAction:action2];
            [alertController showWithAnimated:YES];
    
        }];

    }
    return _BizWX;
}

-(BaseLab *)BizAddr{
    if (!_BizAddr) {
        _BizAddr = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 0, 0) text:@"商家地址" font:12 textColor:[UIColor blackColor] isBold:NO numberOfLines:1];
        _BizAddr.font = [UIFont fontWithName:@"PingFangSC-Medium" size:14];

    }
    return _BizAddr;
}

-(BaseLab *)BizAddrSub{
    if (!_BizAddrSub) {
        _BizAddrSub = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 0, 0) text:@"商家子地址" font:12 textColor:[UIColor blackColor] isBold:NO numberOfLines:1];
        _BizAddrSub.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
    }
    return _BizAddrSub;
}

-(BaseLab *)BizNametext{
    if (!_BizNametext) {
        _BizNametext = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 0, 0) text:@"微信" font:12 textColor:[UIColor blackColor] isBold:NO numberOfLines:1];
        _BizNametext.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
    }
    return _BizNametext;
}

-(BaseLab *)BizPhonetext{
    if (!_BizPhonetext) {
        _BizPhonetext = [[BaseLab alloc]initializeFrame:CGRectMake(0, 0, 0, 0) text:@"电话" font:12 textColor:[UIColor blackColor] isBold:NO numberOfLines:1];
        _BizPhonetext.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
    }
    return _BizPhonetext;
}



////根据后台设置
//imgeMap;
//BizName;
//BizPhone;
//BizWX;
//BizAddr;
//BizAddrSub;
//
//
////不变化
//imgeMapIcon;
//BizNameIcon;
//BizNametext;
//BizPhonetext;

@end
